package com.coincalf.service;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.coincalf.dto.CoinInfoDto;
import com.coincalf.entity.Coin;
import com.baomidou.mybatisplus.service.IService;
import com.coincalf.framework.constants.Constant;

import java.util.List;

/**
 * <p>
 * 币种配置信息 服务类
 * </p>
 *
 * @author qiang
 * @since 2018-05-12
 */
public interface CoinService extends IService<Coin>, Constant {

    /**
     * 根据主键查询币种信息
     *
     * @param coinId 币种ID
     * @return
     */
    Coin queryById(long coinId);

    /**
     * 根据类型查询币种信息
     *
     * @param type 币种类型
     * @return
     */
    @Cached(name = CACHE_KEY_COIN, expire = 120, cacheType = CacheType.LOCAL)
    Coin queryByType(String type);

    /**
     * 根据币种名称查询币种RPC SERVER URL
     *
     * @param coinName 币种名称
     * @return
     */
    @Cached(name = CACHE_KEY_COIN_NAME, expire = 600, cacheType = CacheType.LOCAL)
    String queryServerUrl(String coinName);

    /**
     * 根据币种名称查询币种RPC SERVER URL
     *
     * @param coinName 币种名称
     * @return
     */
    @Cached(name = CACHE_KEY_COIN_INFO, expire = 600, cacheType = CacheType.LOCAL)
    CoinInfoDto queryInfo(String coinName);

    /**
     * 根据所有主链币种
     */
    @Cached(name = CACHE_KEY_COINS, expire = 600, cacheType = CacheType.LOCAL)
    List<Coin> queryMainCoins();

    /**
     * 根据所有主链币种
     */
    @Cached(name = "coin:infos", expire = 120, cacheType = CacheType.LOCAL)
    List<CoinInfoDto> selectContractAddressesByMainCoinId(Long mainCoinId);

    @Cached(name = "coin:mainId", expire = 600, cacheType = CacheType.LOCAL)
    Long selectMainCoinIdByCoinId(Long coinId);

    @Cached(name = CACHE_KEY_COIN, expire = 600, cacheType = CacheType.LOCAL)
    String selectCoinNameByCoinId(Long coinId);
}
